package com.xiongwei.collection;

import java.util.HashMap;
import java.util.Map;

/**
 * Map是一种映射表,可通过key快速查找value
 * 可通过foreach遍历keySet(),也可通过foreach遍历entrySet(),直接获取key-value
 *
 * 最常用的Map实现是HashMap
 *
 * @author XiongWei
 * @date 2021/1/7
 */
public class MapUse {

    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("kobe", 24);
        map.put("jame", 23);
        //keySet()
        for (String key : map.keySet()) {
            Integer value = map.get(key);
            System.out.println("key-value: " + key + ":" + value);
        }
        //entrySet()
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println("key-value: " + entry.getKey() + ":" + entry.getValue());
        }

        Integer kobe = map.remove("kobe");
    }
}
